import React from 'react';
import { Row, Col } from 'antd';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import { intervalMap } from '../../util/common';
//集成登录元素
class OutterSysCom extends React.Component {
	constructor(props) {
		super(props);
		this.handleOnClick = this.handleOnClick.bind(this);
	}
	handleOnClick(routeUrl, linkUrl) {
		const { esetting={} } = this.props;
		const { linkmode='1' } = esetting;
		let url = '';
		if (routeUrl !== '' && routeUrl !== undefined) {
			// url = '/wui/index.jsp#/main' + routeUrl;
			url = '/spa/integration/static4engine/engine.html#/main' + routeUrl;
		} else {
			url = linkUrl;
		}

        if (url) {
            if (linkmode == '1'){ // 当前页打开
                if (window.doThemeAction) {
                    window.doThemeAction('onLoadMain',{url});
                } else {
                    window.location.href = url;
                }
            }else{
                window.open(url, '_blank');
            }
		}
	}
	render() {
		const { data, esetting } = this.props;
		const { displaytype, linkmode, displayLayout } = esetting;
		const num = parseInt(displayLayout); //显示布局 几列
		const colArr = new Array;
		for (var i = 0; i < num; i++) {
			colArr.push(i);
		}
		let style = {};
		if(num == '2'){
            style = {
            	width: '50%',
				float: 'left',
				// paddingLeft: '25%'
			}
		}else if(num == '3'){
            style = {
                width: '33%',
                float: 'left',
                // paddingLeft: '11%'
            }
		}
		let html = colArr.map(i => {
			if ('1' === displaytype) { //左图式
				const dhtml = new Array;
				const ihtml = new Array;
				intervalMap(data, (obj, j) => {
					const n = i + j;
					const item = data[n];
					if (item) {
						let { name, routeUrl, linkUrl, url, width, height } = item;
						height = height || '35';
						width = width || '35';
                        name && dhtml.push(<div style={{ height: (parseInt(height) + 5), lineHeight: (parseInt(height) + 5) + 'px', marginLeft: '10px' }}><a style={{ color: '#000000' }} href="javascript:void(0);" onClick={this.handleOnClick.bind(this, routeUrl, linkUrl)}>{name}</a></div>);
                        url && ihtml.push(
							<div>
								<a target={Number(linkmode) === 2 ? "_blank" : "_self"} href="javascript:void(0);" onClick={this.handleOnClick.bind(this, routeUrl, linkUrl)}>
									<img height={height} width={width} src={url} />
								</a>
							</div>);
					}
				}, num);
				return <div style={style}>
					{/*<Col span={1}>{ihtml}</Col>*/}
					{/*<Col span={24 / num - 1}>{dhtml}</Col>*/}
					<div style={{float: 'left'}}>{ihtml}</div>
					<div style={{float: 'left'}}>{dhtml}</div>
				</div>
			} else { //上图式
				let ohtml = intervalMap(data, (obj, j) => {
					const n = i + j;
					const item = data[n];
					let dHtml = <div />;
					let iHtml = <div />;
					if (item) {
						let { name, routeUrl, linkUrl, url, width, height } = item;
						height = height || '35px';
						width = width || '35px';
						dHtml = <div style={{ height: height, lineHeight: height + 'px' }}><a style={{ color: '#000000' }} href="javascript:void(0);" onClick={this.handleOnClick.bind(this, routeUrl, linkUrl)}>{name}</a></div>;
						iHtml = <div><a href="javascript:void(0);" onClick={this.handleOnClick.bind(this, routeUrl, linkUrl)}><img height={height} width={width} src={url} /></a></div>;
					}
					return <div>
						{iHtml}{dHtml}
					</div>
				}, num);
				return <div style={{ textAlign: 'center' }}>
					<Col ecId={`${this && this.props && this.props.ecId || ''}_Col@oet7g9@${i}`} span={24 / num}>{ohtml}</Col>
				</div>
			}
		});
		return <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@k7xko1`}>{html}</Row>
	}
}

import { WeaErrorPage, WeaTools } from 'ecCom';
class MyErrorHandler extends React.Component {
	render() {
		const hasErrorMsg = this.props.error && this.props.error !== "";
		return (
			<WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@z6pcj0`} msg={hasErrorMsg ? this.props.error : getLabel(385218,"对不起，该页面异常，请联系管理员！")} />
		);
	}
}
OutterSysCom = WeaTools.tryCatch(React, MyErrorHandler, { error: "" })(OutterSysCom);
export default OutterSysCom;